package com.zking.routers;

import com.zking.handers.UserHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.*;

import static org.springframework.web.reactive.function.server.RequestPredicates.*;

/**
 * mvc 总入口
 */
@Configuration
public class AllRouters {

    @Bean
    RouterFunction<ServerResponse> userRouter(UserHandler handler){
        return RouterFunctions.nest(
                //相当于类上面的@RequestMapping("/user)
                RequestPredicates.path("/user"),
                //下面的相当于类里面的@RequestMapping("/)
                RouterFunctions.route(RequestPredicates.GET("/"),
                handler::getAllUser)
                //创建用户
                .andRoute(POST("/").and(accept(MediaType.APPLICATION_JSON)),
                handler::createUser)
                //删除用户
                .andRoute(DELETE("/{id}"),handler::deleteUser)
        );


    }
}
